<template>
  <div>
    <el-form
      class="app-container"
      ref="elForm"
      :model="logList"
      size="medium"
      :inline="true"
      label-width="100px"
    >
      <el-form-item label="用户来源:" prop="type">
        <el-select
          v-model="logList.type"
          placeholder="请选择状态"
          clearable
          :style="{ width: '100%' }"
        >
          <el-option
            v-for="(item, index) in field101Options"
            :key="index"
            :label="item.label"
            :value="item.label"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="注册日期:" prop="registertime">
        <el-date-picker
          v-model="logList.registertime"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          :style="{ width: '100%' }"
          placeholder="请选择提交时间"
          clearable
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="用户名:" prop="userid">
        <el-input
          v-model="logList.userid"
          placeholder="请输入用户名"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item label="姓名:" prop="name">
        <el-input
          v-model="logList.name"
          placeholder="请输入姓名"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item label="手机号:" prop="tel">
        <el-input
          v-model="logList.tel"
          placeholder="请输入手机号"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item label prop="field107">
        <el-button
          type="primary"
          size="medium"
          v-hasPermi="['userManagement:userList:query']"
          @click="search"
          >搜索</el-button
        >
      </el-form-item>
    </el-form>
    <!-- 表格 -->
    <el-table
      v-loading="loading"
      :data="tableData"
      border
      style="width: 95%; margin: auto"
      :header-cell-style="{ background: '#f7f7f7' }"
    >
      <el-table-column
        type="index"
        label="序号"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="userid"
        label="用户名"
        align="center"
      ></el-table-column>
      <el-table-column
        label="姓名"
        prop="name"
        width="120"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="tel"
        label="手机号"
        align="center"
      ></el-table-column>

      <el-table-column
        prop="type"
        label="用户来源"
        align="center"
      ></el-table-column>
      <el-table-column prop="registertime" label="注册时间" align="center">
        <template slot-scope="scope">{{
          newDate(scope.row.registertime)
        }}</template>
      </el-table-column>
      <el-table-column prop="" label=" 最后登录时间" width="155" align="center">
        <!-- <template slot-scope="scope">{{
          newDate(scope.row.checkedtime)
        }}</template> -->
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button
            type="text"
            size="small"
            v-hasPermi="['userManagement:userList:edit']"
            @click="checkDetail(scope.row)"
            >查看</el-button
          >
          <el-button
            type="text"
            size="small"
            style="color:red"
            v-hasPermi="['userManagement:userList:edit']"
            @click="reset(scope.row)"
            >重置密码</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <!-- <el-pagination
      class="pagination"
      align="right"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="logList.page"
      :page-size="logList.pageSize"
      background
      :total="total"
    ></el-pagination> -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="logList.pageNum"
      :limit.sync="logList.pageSize"
      @pagination="getSuggestion()"
    />
    <!-- 回复弹出框 -->
    <el-dialog
      title="重置密码"
      width="500px"
      :visible.sync="dialogVisible"
      style="margin-top: 10%"
    >
      <el-row type="flex" class="row-bg" justify="center">
        <el-col style="margin-left:20px">
          <div class="grid-content bg-purple">
            重置用户登录密码,初始密码为12345678
          </div>
        </el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="getSubmits">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { list, resetPwd } from "@/api/userManagement/userList";
import utils from "../../js/index";
export default {
  name: "UserList",
  components: {},
  props: [],
  data() {
    return {
      // 用户列表
      tableData: [],
      // 重置按钮框
      dialogVisible: false,
      // 数据总条数
      total: 0,
      // 加载中
      loading: true,
      // 用户id
      userId: "",
      field101Options: [
        {
          label: "支付宝用户",
          value: 2
        },
        {
          label: "微信用户",
          value: 1
        },
        {
          label: "个人会员",
          value: 0
        },
        {
          label: "网站用户",
          value: 3
        },
        {
          label: "鼎商",
          value: 4
        },
        {
          label: "小程序",
          value: 5
        },
        {
          label: "豫事办",
          value: 6
        },
        {
          label: "发改委",
          value: 7
        }
      ],
      // 查询列表传递的参数
      logList: {
        pageNum: 1,
        pageSize: 10,
        registertime: "",
        type: "",
        userid: "",
        nameL: "",
        tel: ""
      }
    };
  },
  computed: {},
  created() {
    this.getSuggestion();
  },
  mounted() {},
  methods: {
    //每页条数改变时触发 选择一页显示多少行
    handleSizeChange(val) {
      this.currentPage = 1;
      this.pageSize = val;
    },
    //当前页改变时触发 跳转其他页
    handleCurrentChange(val) {
      this.logList.page = val;
      this.currentPage = val;
    },
    // 用户列表
    getSuggestion() {
      list(this.logList).then(response => {
        if (response.code == 200) {
          this.tableData = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      });
    },
    // 搜索按钮
    search() {
      list(this.logList).then(response => {
        this.tableData = response.rows;
        this.total = response.total;
      });
    },
    // 日期格式化
    newDate(date) {
      return utils.utils.NewDate(date);
    },
    // 查看按钮
    checkDetail(val) {
      // 跳转到详情页面
      this.$router.push({
        path: `./userDetails`,
        query: {
          id: val.id
        }
      });
    },
    // 重置密码按钮
    reset(val) {
      this.userId = val.id;
      this.dialogVisible = true;
    },
    // 密码重置
    getSubmits() {
      resetPwd({ id: this.userId }).then(response => {
        if (response.code == 200) {
          this.dialogVisible = false;
          this.getSuggestion();
          this.$message({
            showClose: true,
            message: "重置成功",
            type: "success"
          });
        }
      });
    }
  }
};
</script>

<style>
.pagination {
  margin-top: 2%;
  margin-bottom: 2%;
}
.one-txt-cut {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
</style>
